package start.spring.basic.flowable.service.lclbgl.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import start.spring.basic.constant.CommonConstant;
import start.spring.basic.flowable.dao.BpmLclbMapper;
import start.spring.basic.flowable.entity.BpmLclb;
import start.spring.basic.flowable.service.BaseServiceImpl;
import start.spring.basic.flowable.service.lclbgl.IBpmLclbService;
import start.spring.basic.page.PageQuery;
import start.spring.basic.page.PageResult;
import start.spring.basic.util.common.StringUtil;

/**
 * 流程类别管理Service业务层处理
 * 
 * @author xuyy
 * @date 2023-08-17
 */
@Service
public class BpmLclbServiceImpl extends BaseServiceImpl implements IBpmLclbService {
    
    @Autowired
    private BpmLclbMapper bpmLclbMapper;

    /**
     * 查询流程类别管理列表
     * 
     * @param bpmLclb 流程类别管理
     * @return 流程类别管理
     */
    @Override
    public PageResult<BpmLclb> selectBpmLclbPageList(PageQuery pageQuery,BpmLclb bpmLclb) {
        IPage<BpmLclb> page = super.getPage(pageQuery);
        QueryWrapper<BpmLclb> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(!StringUtil.isEmpty(bpmLclb.getId()), BpmLclb::getId, bpmLclb.getId());
        queryWrapper.lambda().like(!StringUtil.isEmpty(bpmLclb.getLclbName()), BpmLclb::getLclbName, bpmLclb.getLclbName());
        queryWrapper.lambda().like(!StringUtil.isEmpty(bpmLclb.getBz()), BpmLclb::getBz, bpmLclb.getBz());
        queryWrapper.lambda().eq(bpmLclb.getXh()!=null, BpmLclb::getXh, bpmLclb.getXh());
        if(!StringUtil.isEmpty(bpmLclb.getBeginCreateTime()) && !StringUtil.isEmpty(bpmLclb.getEndCreateTime())) {
        	queryWrapper.lambda().between(BpmLclb::getCreateTime, bpmLclb.getBeginCreateTime() + CommonConstant.SURFIX_DATE_BEGIN, bpmLclb.getEndCreateTime() + CommonConstant.SURFIX_DATE_END);
        }
        page = this.bpmLclbMapper.selectPage(page, queryWrapper);
        return super.getPageResult(page);
    }
    
    /**
     * 查询全量流程类别管理
     * 
     * @param bpmLclb 流程类别管理
     * @return 流程类别管理
     */
    @Override
    public List<BpmLclb> selectBpmLclbList(BpmLclb bpmLclb) {
        QueryWrapper<BpmLclb> queryWrapper = new QueryWrapper<>();
        if(bpmLclb!=null) {
        	queryWrapper.lambda().eq(!StringUtil.isEmpty(bpmLclb.getId()), BpmLclb::getId, bpmLclb.getId());
            queryWrapper.lambda().like(!StringUtil.isEmpty(bpmLclb.getLclbName()), BpmLclb::getLclbName, bpmLclb.getLclbName());
            queryWrapper.lambda().like(!StringUtil.isEmpty(bpmLclb.getBz()), BpmLclb::getBz, bpmLclb.getBz());
            queryWrapper.lambda().eq(bpmLclb.getXh()!=null, BpmLclb::getXh, bpmLclb.getXh());
            if(!StringUtil.isEmpty(bpmLclb.getBeginCreateTime()) && !StringUtil.isEmpty(bpmLclb.getEndCreateTime())) {
            	queryWrapper.lambda().between(BpmLclb::getCreateTime, bpmLclb.getBeginCreateTime() + CommonConstant.SURFIX_DATE_BEGIN, bpmLclb.getEndCreateTime() + CommonConstant.SURFIX_DATE_END);
            }
        }
        return this.bpmLclbMapper.selectList(queryWrapper);
    }

    /**
     * 新增流程类别管理
     * 
     * @param bpmLclb 流程类别管理
     * @return 结果
     */
    @Override
    public int insertBpmLclb(BpmLclb bpmLclb) {
        return this.bpmLclbMapper.insert(bpmLclb);
    }

    /**
     * 修改流程类别管理
     * 
     * @param bpmLclb 流程类别管理
     * @return 结果
     */
    @Override
    public int updateBpmLclb(BpmLclb bpmLclb) {
    	bpmLclb.setUpdateTime(new Date());
    	UpdateWrapper<BpmLclb> updateWrapper = new UpdateWrapper<>();
    	updateWrapper.lambda().eq(BpmLclb::getId, bpmLclb.getId());
        return this.bpmLclbMapper.update(bpmLclb, updateWrapper);
    }

    /**
     * 批量删除流程类别管理
     * 
     * @param IDs 需要删除的流程类别管理主键
     * @return 结果
     */
    @Override
    public int deleteBpmLclbByIDs(List<String> IDs) {
        return this.bpmLclbMapper.deleteBatchIds(IDs);
    }
	
}
